<script type="text/javascript">
    const numStr =["零","一","二","三","四","五","六","七","八","九"];
    const numUnit =["","","十","百","千","万","亿"];
    var num = prompt("请输入小于十位的值");
    var len = num.length;//记录剩余没转换的长度
    var curLen = len;
    var j = 0;//指向未转换的值的头部位置
    var res;
    while(len > 8){//处理千万数值以上
        var count = 0;//用于判断是否有0
        var tempLen = len-8;
        res += numStr[num.charAt(j++)]+numUnit[tempLen];
        len--;
        //判断后面的值是否有0
        for(let i = j; i < num.length-8; i++){
            if(num.charAt(i) == '0') {
                len--;
                j++;
                count++;
            }else{
                break;
            }
        }
        //说明有0
        if(j == num.length - 8) res += "亿";//说明该区域剩余全为0,或者该区域已经转换结束
        else if(count != 0) res += "零";//说明有0
    }
    if(curLen > 8 && num.charAt(j-1) == 0) res+="零"
    while(len > 4){//处理万数值以上
        var count = 0;//用于判断是否有0
        var tempLen = len-4;
        if(num.charAt(j) != 0) res += numStr[num.charAt(j++)]+numUnit[tempLen];
        len--;
        //判断该区域的值是否有0
        for(let i = j; i < num.length-4; i++){
            if(num.charAt(i) == '0') {
                len--;
                j++;
                count++;
            }else{
                break;
            }
        }
        if(j == num.length - 4) res += "万";//说明该区域剩余全为0,或者该区域已经转换结束
        else if(count != 0 ) res += "零";//说明有0
    }
    if(curLen > 4 && num.charAt(j-1) == 0) res+="零"
    while(len > 0){//处理万数值以下
        var count = 0;//用于判断是否有0
        if(num.charAt(j) != 0) res += numStr[num.charAt(j++)]+numUnit[len--];
        //判断后面的值是否有0
        for(let i = j; i < num.length; i++){
            if(num.charAt(i) == '0') {
                len--;
                j++;
                count++;
            }else{
                break;
            }
        }
        //说明该区域全为0,或者已经转换结束
        if(j == num.length){}
        else if(count != 0) res += "零";//说明有0
    }
    alert(res);
</script>